<?php
  defined('_JEXEC') or die('Retricted Access');
  $arr_remove_folder = array('jaerrors','jashortlist','jafeeds');
  $arr_remove_file = array('index.html','suggesturl.php');
  $arr_remove_ext = array('xml','html');
  function char($parser,$data)
	{
	  	echo $data;
	}
?>

<form name="adminForm" action="index.php" method="post">

  <div style="width:100%;">
  	<?php echo $this->menu(); ?>
  	<br/>
    <table class="adminlist">
    	<thead>
    		<th align="center">
    			<?php echo JText::_( 'Folder' ); ?>
    		</th>
    		<th>
	    		<table class="adminlist">
	    			<tr>
	            		<td align="center" width="5%" style="border: 0px none ; background-color: rgb(240, 240, 240);"><?php echo JText::_( '#' ); ?></td>
	            		<td width="25%" style="border: 0px none ; background-color: rgb(240, 240, 240);"><?php echo JText::_('File Name'); ?></td>            		          		            		
						<td width="50%" style="border: 0px none ; background-color: rgb(240, 240, 240);"><?php echo JText::_('Description'); ?></td>
						<td align="center" width="10%" style="border: 0px none ; background-color: rgb(240, 240, 240);"><?php echo JText::_('Status'); ?></td>
						<td align="center" width="10%" style="border: 0px none ; background-color: rgb(240, 240, 240);"><?php echo JText::_('Action'); ?></td>
	            	</tr>
	    		</table>
    		</th>
    	</thead>
		<tbody>
    	<?php
    	$folders = $this->folders;
    	$files = $this->files;
    	for($i = 0; $i < count($folders); $i++){
    		$folder = $folders[$i];	
    		if (in_array($folder,$arr_remove_folder))
    			continue;	
    		?>
    		<tr class="row<?php echo $i%2; ?>">
        		<td align="center">
        		<?php 
        			$folder_name = strtoupper(substr($folder,2,1)).substr($folder,3,strlen($folder)-2);
        			echo '<b>'.$folder_name.'</b>'; 
        		?>
        		</td>    
        		<td align="left">
        			<table class="adminlist">
        			
        				<?php 
        					$count_col = 0;
        					for($k = 0; $k < count($files[$i]); $k++){
        				?>
        				<?php 
        					if (in_array($files[$i][$k],$arr_remove_file))
        						continue;
        					if (in_array(substr($files[$i][$k],strlen($files[$i][$k])-3),$arr_remove_ext))	
        						continue;
        					$count_col++;
        					?>
        				<tr>
        					<td align="center" width="5%"><?php echo $count_col; ?></td>
        					
        				
        					<td width="25%">
        					<!--<a href="<?php echo JRoute::_( 'index.php?option='. $this->lists['option'] .'&view=jacustomtmpl&task=edit&folder='.$folder.'&file='.$files[$i][$k] ); ?>">-->
        						<?php echo '<b>'.$files[$i][$k].'</b>'; ?>
        					<!--</a>-->
        					</td>
        					<td width="50%">
        					<?php 
	        					$parser=xml_parser_create();	
								xml_set_character_data_handler($parser,"char");
								$fp=@fopen(JPATH_COMPONENT_SITE.DS.'views'.DS.$folder.DS.'tmpl'.DS.substr($files[$i][$k],0,strlen($files[$i][$k])-3)."xml","r");
								
								while ($data=fread($fp,4096))
								{
								  	xml_parse($parser,$data,feof($fp)) or
								  	die (sprintf("XML Error: %s at line %d",
								  	xml_error_string(xml_get_error_code($parser)),
								  	xml_get_current_line_number($parser)));
								}
								
								xml_parser_free($parser);
        					?>
        					</td>
        					<td align="center" width="10%">
        						<?php if(JFile::exists(JPATH_SITE . DS. 'templates'. DS . $this->template. DS. 'html'. DS. 'com_jajobboard' . DS. $folder .DS .$files[$i][$k] )){ 
								$confirm = JText::_("Are you sure you want to restore this layout? If you choose Yes, the changes will be lost. Layout will be restored to the original default.");
       								?>
       								<img src="components/com_jajobboard/images/modified.gif" title="<?php echo JText::_('Modified')?>" alt="<?php echo JText::_('Modified')?>"/>
       							 	 [<a onclick="return confirm('<?php echo $confirm?>')" href="index.php?option=com_jajobboard&view=jacustomtmpl&task=restore&&folder=<?php echo $folder.'&file='.$files[$i][$k]?>" title="<?php echo JText::_('Restore to default')?>"><?php echo JText::_('Restore')?></a>]
       							 <?php }else{?>
       							 	<img src="components/com_jajobboard/images/notmodified.gif" title="<?php echo JText::_('Not Modified')?>" alt="<?php echo JText::_('Not Modified')?>"/>
       							 <?php }?>
        					</td>
        					<td align="center" width="10%">
        						<a href="<?php echo JRoute::_( 'index.php?option='. $this->lists['option'] .'&view=jacustomtmpl&viewmenu=0&task=edit&folder='.$folder.'&file='.$files[$i][$k] ); ?>">
        						<?php echo JText::_('Edit'); ?>
        						</a>
        						
        					</td>
        				</tr>
        				<?php }?>
        			</table>	
        		</td>
        		<td>&nbsp;</td>            		          		            	
        	</tr>
    	<?php
    	
		}
    	?>
		</tbody>
	</table>
  </div>

	
	<input type="hidden" name="option" value="<?php echo $this->lists['option']; ?>" />
	<input type="hidden" name="view" value="jacustomtmpl" />
	<input type="hidden" name="task" value="" />
	<?php echo JHTML::_( 'form.token' ); ?>	
 </form>
